package zw_801_900.zw_896_单调数列;

class Solution {

    public static void main(String[] args) {
        int[] nums = {6,5,4,4};
        boolean b = isMonotonic(nums);
        System.out.println(b);
    }

    /**
     * 反推：不可能同时出现大于和小于
     * @param nums
     * @return
     */
    public static boolean isMonotonic(int[] nums) {
        boolean inc = true, dec = true;
        int n = nums.length;
        for (int i = 0; i < n - 1; ++i) {
            if (nums[i] > nums[i + 1]) {
                inc = false;
            }
            if (nums[i] < nums[i + 1]) {
                dec = false;
            }
        }
        return inc || dec;
    }
}
